{% load extra %}

<div class="row">
  <div class="col-xs-12">
    <div class="col-xs-1"><h3><i class="{% if checks_type == "All" %}fa fa-cog{% else %}glyphicon glyphicon-{% if checks_type == "Http" %}arrow-up{% elif checks_type == "Jenkins" %}ok{% else %}signal{% endif %}{% endif %}"></i></h3></div>
    <div class="col-xs-8"><h3>{{ checks_type }} checks</h3></div>
    <div class="col-xs-3 text-right">
      <h3>
      &nbsp;{% if checks_type == "All" or checks_type == "Graphite" %}
      <a href="{% url create-check %}?service={{ service.id }}" class=""><i class="glyphicon glyphicon-plus" title="Add new metric check"></i><i class="glyphicon glyphicon-signal" title="Add new metric check"></i></a>
      {% endif %}
      {% if checks_type == "All" or checks_type == "Http" %}
      &nbsp;<a href="{% url create-http-check %}?service={{ service.id }}" class="" title="Add new Http check"><i class="glyphicon glyphicon-plus"></i><i class="glyphicon glyphicon-arrow-up"></i></a>
      {% endif %}
      {% if checks_type == "All" or checks_type == "Jenkins" %}
      &nbsp;<a href="{% url create-jenkins-check %}?service={{ service.id }}" class="" title="Add new Jenkins check"><i class="glyphicon glyphicon-plus"></i><i class="glyphicon glyphicon-ok"></i></a>
      {% endif %}
      </h3>
    </div>
  </div>
</div>
<hr>
<div class="row">
  <div class="col-xs-12">
    {% if not checks %}
      <div class="col-xs-11 col-xs-offset-1">No checks configured</div>
    {% else %}
    <table class="table bootstrap-datatable datatable">
      <thead>
        <tr>
          <th>Name</th>
          <th>Status</th>
          <th></th>
          {% if checks_type == "All" %}
          <th class="text-center">Type</th>
          {% endif %}
          <th>Test description</th>
          <th>Importance</th>
          <th>Service(s)</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
      {% for check in checks %}
        <tr class="{% if check.active %}enabled{% else %}warning{% endif %}">
          <td title="{{ check.name }} - alerts {% if check.active %}enabled{% else %}disabled{% endif %}">
            <a href="{% url check pk=check.id %}">{{check.name}}</a>
          </td>
          <td title="{{ check.calculated_status }}">
            {% if check.active %}
            <span class="label label-{% if check.calculated_status == 'passing' %}success{% else %}danger{% endif %}">
              {{ check.calculated_status|capfirst }}
            </span>
            {% else %}
            <span class="label label-warning">Disabled</span>
            {% endif %}
          </td>
          <td title="Last result from {{ check.last_run|timesince }} ago (rightmost is newest)" class="sparktristate" values="{{ check.cached_health }}">
            {% if not check.recent_results %}
            No results available
            {% endif %}
          </td>
          {% if checks_type == "All" %}
          <td class="text-center">
          <i class="glyphicon glyphicon-{% if check.polymorphic_ctype.model == 'graphitestatuscheck' %}signal{% elif check.polymorphic_ctype.model == 'httpstatuscheck' %}arrow-up{% elif check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}ok{% endif %}"></i>
          </td>
          {% endif %}
          <td title="">
            {% if check.polymorphic_ctype.model == 'graphitestatuscheck' %}{{ check.metric|truncatechars:70 }} {{ check.check_type }} {{ check.value }}{% if check.expected_num_hosts %} (from {{ check.expected_num_hosts }} hosts){% endif %}{% elif check.polymorphic_ctype.model == 'httpstatuscheck' %}Status code {{ check.status_code }} from {{ check.endpoint }}{% if check.text_match %}; match text /{{ check.text_match }}/{% endif %}{% elif check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}Monitor job {{ check.name }}{% if check.max_queued_build_time %}; check no build waiting for >{{ check.max_queued_build_time }} minutes{% endif %}{% endif %}
          </td>
          <td>{{ check.get_importance_display }}</td>
          <td>
            {% for service in check.service_set.all %}
            <a href="{% url service pk=service.id %}">{{ service.name }}</a>
            {% if forloop.last %}
            {% else %}
            /
            {% endif %}
            {% endfor %}
            {% if not check.service_set.all %}
            <span class="label label-warning">No service</span>
            {% endif %}
          </td>
          <td class="text-right">
            <a class="btn btn-xs" href="{% if check.polymorphic_ctype.model == 'graphitestatuscheck' %}{% url update-check pk=check.id %}{% elif check.polymorphic_ctype.model == 'httpstatuscheck' %}{% url update-http-check pk=check.id %}{% elif check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}{% url update-jenkins-check pk=check.id %}{% endif %}">
              <i class="glyphicon glyphicon-edit"></i><span class="break"></span>
            </a>
            <a class="btn btn-xs" href="{% url run-check pk=check.id %}">
              <i class="glyphicon glyphicon-refresh"></i><span class="break"></span>
            </a>
            {% if checks_type == "Jenkins" %}
            <a class="btn btn-xs" href="{% jenkins_human_url check.name %}">
              <i class="glyphicon glyphicon-link"></i><span class="break"></span>
            </a>
            {% endif %}
          </td>
        </tr>
      {% endfor %}
      </tbody>
    </table>
    {% endif %}
  </div>
</div>